package top.chenfu1201.clientApi.exception;

import lombok.Data;

public class GlobalException extends RuntimeException {

    private Integer code;

    private String msg;

    private Object data;

    public GlobalException() {
    }

    public GlobalException(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public GlobalException(ExceptionEnum exceptionEnum, Object data) {
        this.code = exceptionEnum.getCode();
        this.msg = exceptionEnum.getMsg();
        this.data = data;
    }

    public static GlobalException defaultSuccess() {
        GlobalException success = new GlobalException();
        success.code = ExceptionEnum.SYS_OK.getCode();
        success.msg = ExceptionEnum.SYS_OK.getMsg();
        return success;
    }

    public static GlobalException defaultFail() {
        GlobalException fail = new GlobalException();
        fail.code = ExceptionEnum.SYS_ERROR.getCode();
        fail.msg = ExceptionEnum.SYS_ERROR.getMsg();
        return fail;
    }

    @Override
    public String toString() {
        return "GlobalException{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
